﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class cn_feedback2 : System.Web.UI.Page
{
    protected string _cid = "43";
    protected void Page_Load(object sender, EventArgs e)
    {
        _cid = Request.QueryString["cid"];
        if (string.IsNullOrEmpty(_cid))
        {
            _cid = ColumnHelp.GetFirstColumnId(16);
        }
        else
        {
            if (!Whir.Common.WebHelper.Utils.IsInt(_cid))
                _cid = ColumnHelp.GetFirstColumnId(16);
        }
        if (!IsPostBack)
        {
            if (Session["UserName"] != null)
            {

                GetInfo();
            }
            GetTipsInfo();
        }
    }

    private void GetInfo()
    {
        string sql = string.Format("select * from Whir_U_Users where LoginName='{0}' ", Session["UserName"].ToString());
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dt != null && dt.Rows.Count > 0)
        {

            txtName.Value = dt.Rows[0]["TrueName"].ToString();
            txtTel.Value = dt.Rows[0]["LinkTel"].ToString();
            txtCompanyName.Value = dt.Rows[0]["CompanyName"].ToString();
            txtAddress.Value = dt.Rows[0]["Address"].ToString();
           



        }

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string sql = "insert into Whir_U_Message (TypeID,CreateDate,Person,Tel,CompanyName,Address,Content,BM,Mobie,Course,applyNum) values (@TypeID,@CreateDate,@Person,@Tel,@CompanyName,@Address,@Content,@BM,@Mobie,@Course,@applyNum)";

       
        SqlParameter[] pa =
        {
            new SqlParameter("@TypeID",_cid),
            new SqlParameter("@CreateDate",DateTime.Now),
            new SqlParameter("@Person",txtName.Value),
            new SqlParameter("@Tel",txtTel.Value),
            new SqlParameter("@CompanyName",txtCompanyName.Value),
            new SqlParameter("@Address",txtAddress.Value),  
            new SqlParameter("@Content",txtContent.Value),
            new SqlParameter("@BM",""),  
            new SqlParameter("@Mobie",txtMobiel.Value),
            new SqlParameter("@Course",txtCourse.Value),
            new SqlParameter("@applyNum",txtapplyNum.Value)
        };
        int count = Whir.SQLServerDAL.DbHelperSQL.ExecuteSql(sql, pa);
        if (count > 0)
        {

            Whir.Common.WebHelper.JsHelper.redirect(this.Page, "发送成功!", "feedback2.aspx?cid=" + _cid);


        }
        else { Whir.Common.WebHelper.JsHelper.Alert(this.Page, "发送失败!"); }
    }

    protected string GetReplayTime(string dateTime)
    {
        if (!string.IsNullOrEmpty(dateTime))
        {
            return string.Format("({0})", Convert.ToDateTime(dateTime).ToString("yyyy-MM-dd"));
        }

        return "";
    }
    private void GetTipsInfo()
    {
        ltrTips.Text = ColumnHelp.GetColumnName(_cid);
    }
}
